﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class databasehelper
    {
        private static string constr = "server=.;database=user1;uid=sa;pwd=123456";
        private static string sql = "select * from commodity";


        public static void printUserInfoReader()
        {
            string connStr = "server=.;database=ado;uid=sa;pwd=123456.";

            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();

            string sql = "select * from [Table]";

            SqlCommand cmd = new SqlCommand(sql, conn);

            var sdr = cmd.ExecuteReader();

            while (sdr.Read())
            {

                Console.WriteLine(sdr["userName"] + "," + sdr["userId"]);
            }
            conn.Close();
        }
        public static void PrintUserInfoAdaper(string connStr)
        {
            SqlDataAdapter dat = new SqlDataAdapter(sql, connStr);
            DataTable set = new DataTable();
            dat.Fill(set);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}", "姓名", "编号", "性别");

            for (int i = 0; i < set.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}", set.Rows[i]["姓名"], set.Rows[i]["编号"], set.Rows[i]["性别"]);

            }
        }
    }
}